﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IProductCommentService
    {
        IQueryable<ProductComment> GetProductComments();
        ProductComment GetProductComment(int id);
        void CreateProductComment(ProductComment productComment);
        void DeleteProductComment(int id);
        void SaveProductComment();
    }
    
    public class ProductCommentService : IProductCommentService
    {
        private readonly IProductCommentRepository productCommentRepository;
        private readonly IUnitOfWork unitOfWork;
        public ProductCommentService(IProductCommentRepository productCommentRepository, IUnitOfWork unitOfWork)
        {
            this.productCommentRepository = productCommentRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IProductCommentService Members

        public IQueryable<ProductComment> GetProductComments()
        {
            var productComments = productCommentRepository.GetAll();
            return productComments;
        }

        public ProductComment GetProductComment(int id)
        {
            var productComment = productCommentRepository.GetById(id);
            return productComment;
        }

        public void CreateProductComment(ProductComment productComment)
        {
            productCommentRepository.Add(productComment);
            SaveProductComment();
        }

        public void DeleteProductComment(int id)
        {
            var productComment = productCommentRepository.GetById(id);
            productCommentRepository.Delete(productComment);
            SaveProductComment();
        }

        public void SaveProductComment()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}